package com.v5ba.factoryBeanDemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yiren
 * @since 2022/9/20
 */
@RestController
public class DemoController {
    @Autowired
    private ApplicationContext applicationContext;
//    @Autowired
//    @Qualifier("userServiceFactory")
//    private UserService userService;
//    @Autowired
//    @Qualifier("&userServiceFactory")
//    private UserServiceFactory userServiceFactory;


    @GetMapping("test")
    public String test(){
        UserServiceFactory demo = applicationContext.getBean(UserServiceFactory.class);

        demo = (UserServiceFactory)applicationContext.getBean("&userServiceFactory");
        demo.test();
        UserService userService = (UserService)applicationContext.getBean("userServiceFactory");
        userService = applicationContext.getBean(UserService.class);
        userService.sayHello();
        //userService.sayHello();
        //userServiceFactory.test();

        return "ok";
    }
}
